package com.example.schoolnewsapp.database;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBHelper extends SQLiteOpenHelper {
    private SQLiteDatabase db;
    private Context mContext;
    //创建注册表
    private static final  String CREATE_USER = "create table User ("
            + "id integer primary key autoincrement,"
            + "name text,"
            + "password text,"
            + "gender text,"
            + "area text,"
            + "birth text,"
            + "describe text)";


    public static final String CREATE_VIDEO = "create table Video ("
            + "id integer primary key autoincrement,"
            + "title text,"
            + "url text,"
            + "coverurl text,"
            + "author text,"
            + "avatar text)";

    public static final String CREATE_COMMENT = "create table Comment ("
            + "id integer primary key autoincrement,"
            + "news_title text,"
            + "news_date text,"
            + "news_author text,"
            + "news_picurl text,"
            + "news_url text,"
            + "context text)";

    public static final String CREATE_FAV_NEWS = "create table Fav_News ("
            + "id integer primary key autoincrement,"
            + "news_title text,"
            + "news_date text,"
            + "news_author text,"
            + "news_picurl text,"
            + "news_url text)";

    public static final String CREATE_DIANZAN_NEWS = "create table dianzan_News ("
            + "id integer primary key autoincrement,"
            + "news_title text,"
            + "news_date text,"
            + "news_author text,"
            + "news_picurl text,"
            + "news_url text)";
    public DBHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext=context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(CREATE_USER);
        db.execSQL(CREATE_VIDEO);
        db.execSQL(CREATE_COMMENT);
        db.execSQL(CREATE_FAV_NEWS);
        db.execSQL(CREATE_DIANZAN_NEWS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists User");
        db.execSQL("drop table if exists Video");
        db.execSQL("drop table if exists Comment");
        db.execSQL("drop table if exists dianzan_News");
        onCreate(db);
    }



}


